<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:p="http://primefaces.org/ui">

    <body>

        <ui:composition template="./TemplatePrincipal.xhtml">

            <ui:define name="top">
                <p:panel>
                    <p:clock mode="client" pattern="HH:mm:ss dd/MM/yy"/>
                </p:panel>
            </ui:define>

            <ui:define name="left">
                <f:view>
                    <h:form>
                        <p:panel>
                            <p:commandButton ajax="false" id ="newCourseButton" value="New" action="CourseCreateEdit" actionListener="#{courseBean.prepareNew}">
                                <p:tooltip for="newCourseButton" value="Add new course..."/>
                            </p:commandButton>
                            <p:commandButton ajax="false" id ="backButton" value="Back" action="PrincipalMenu">
                                <p:tooltip for="backButton" value="Back to main menu..."/>
                            </p:commandButton>
                        </p:panel>
                    </h:form>
                </f:view>

            </ui:define>

            <ui:define name="content">
                <f:view>
                    <h:form id="form">                        
                        <p:panel >
                            <p:dataTable value="#{courseBean.courseList}" var="item" paginator="true" rows="5">
                                <p:column filterBy="#{item.name}">
                                    <f:facet name="header">
                                        <p:outputLabel value="Name"/>
                                    </f:facet>
                                    <p:outputLabel value="#{item.name}"/>
                                </p:column>
                                <p:column>
                                    <f:facet name="header">
                                        <p:outputLabel value="Edit"/>
                                    </f:facet>
                                    <center>
                                        <p:commandButton value="Edit" action="CourseCreateEdit" 
                                                         actionListener="#{courseBean.prepareEdit}"
                                                         id="editCButton" ajax="false">
                                            <p:tooltip for="editCButton" value="Edit selected course..."/>
                                            <f:setPropertyActionListener value="#{item}" target="#{courseBean.course}"/>
                                        </p:commandButton>
                                    </center>
                                </p:column>
                                <p:column>
                                    <f:facet name="header">
                                        <h:outputText value="Details"/>
                                    </f:facet>
                                    <center>
                                        <p:commandButton 
                                            value="See ID" 
                                            update=":form:panel" 
                                            onclick="dialogCourse.show();" 
                                            icon="ui-icon-info" 
                                            id="seeCButton">
                                            <p:tooltip for="seeCButton" value="See ID of selected Course..."/>
                                            <f:setPropertyActionListener value="#{item}" target="#{courseBean.course}"/>
                                        </p:commandButton>
                                    </center>
                                </p:column>
                            </p:dataTable>
                            <p:dialog widgetVar="dialogCourse" modal="true" width="250" 
                                      height="200" showEffect="fade" hideEffect="explode"
                                      resizable="false" position="600 ,150" draggable="false">
                                <h1><h:outputText value="Details..."/></h1>
                                <h:panelGrid columns="2" id="panel">
                                    <p:outputLabel value="ID :"/>
                                    <p:outputLabel value=" #{courseBean.course.id}" title="Id"/>
                                </h:panelGrid>
                            </p:dialog>
                        </p:panel>
                    </h:form>
                </f:view>
            </ui:define>
        </ui:composition>

    </body>
</html>
